package com.novunda.platform.entities;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.novunda.platform.entities.base.DataEntity;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;

/**
 * 邮件信息模型
 * Created by YJY on 2016/9/9.
 */
@Entity
@Table(name = "email_info")
public class EmailInfo extends DataEntity {
    private static final long serialVersionUID = -2608370641051521047L;

    /**
     * id
     */
    private Long id;
    /**
     * 机构
     */
    private String organization;
    /**
     * 邮箱
     */
    private String email;
    /**
     * 邮箱密码
     */
    private String emailPassword;
    /**
     * 邮箱主题
     */
    private String emailTheme;
    /**
     * 端口
     */
    private Integer port;
    /**
     * 服务器地址
     */
    private String serversAddress;
    /**
     * 邮箱内容
     */
    private String emailContent;
    /**
     * 邮箱备注
     */
    private String emailRemarks;

    /**
     * 是否开启ssl
     */
    private boolean openSSL = false;

    /**
     * 是否是默认邮件
     */
    private boolean defaultEmail = false;

    private Office company;    // 归属公司
    private Office office;    // 归属部门

    @Column(name = "default_email")
    public boolean isDefaultEmail() {
        return defaultEmail;
    }

    public void setDefaultEmail(boolean defaultEmail) {
        this.defaultEmail = defaultEmail;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "organization", nullable = false)
    public String getOrganization() {
        return organization;
    }

    public void setOrganization(String organization) {
        this.organization = organization;
    }

    @Column(name = "email", length = 255, nullable = false)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "email_password", nullable = false)
    public String getEmailPassword() {
        return emailPassword;
    }

    public void setEmailPassword(String emailPassword) {
        this.emailPassword = emailPassword;
    }

    @Column(name = "email_theme", length = 255)
    public String getEmailTheme() {
        return emailTheme;
    }

    public void setEmailTheme(String emailTheme) {
        this.emailTheme = emailTheme;
    }

    @Column(name = "port", length = 10)
    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    @Column(name = "servers_address", nullable = false, length = 255)
    public String getServersAddress() {
        return serversAddress;
    }

    public void setServersAddress(String serversAddress) {
        this.serversAddress = serversAddress;
    }

    @Column(name = "email_content", length = 4096)
    public String getEmailContent() {
        return emailContent;
    }

    public void setEmailContent(String emailContent) {
        this.emailContent = emailContent;
    }

    @Column(name = "email_remarks")
    public String getEmailRemarks() {
        return emailRemarks;
    }

    public void setEmailRemarks(String emailRemarks) {
        this.emailRemarks = emailRemarks;
    }

    @ManyToOne
    @JoinColumn(name = "company_id", nullable = false)
    @NotFound(action = NotFoundAction.IGNORE)
    @JsonIgnore
//	@NotNull(message="归属公司不能为空")
    public Office getCompany() {
        return company;
    }

    public void setCompany(Office company) {
        this.company = company;
    }

    @ManyToOne
    @JoinColumn(name = "office_id", nullable = false)
    @NotFound(action = NotFoundAction.IGNORE)
    @JsonIgnore
//	@NotNull(message="归属部门不能为空")
    public Office getOffice() {
        return office;
    }

    public void setOffice(Office office) {
        this.office = office;
    }

    @Column(name = "open_ssl")
    public boolean isOpenSSL() {
        return openSSL;
    }

    public void setOpenSSL(boolean openSSL) {
        this.openSSL = openSSL;
    }

    @Override
    public String toString() {
        return "EmailInfo{" +
                "id=" + id +
                ", organization='" + organization + '\'' +
                ", email='" + email + '\'' +
                ", emailPassword='" + emailPassword + '\'' +
                ", emailTheme='" + emailTheme + '\'' +
                ", port=" + port +
                ", serversAddress='" + serversAddress + '\'' +
                ", emailContent='" + emailContent + '\'' +
                ", emailRemarks='" + emailRemarks + '\'' +
                ", openSSL=" + openSSL +
                ", defaultEmail=" + defaultEmail +
                ", company=" + company +
                ", office=" + office +
                '}';
    }
}
